package com.tenement.service.impl;

import com.github.pagehelper.PageHelper;
import com.tenement.dao.TenementSectorMapper;
import com.tenement.domain.TenementSector;
import com.tenement.domain.TenementUser;
import com.tenement.service.SectorService;
import com.tenement.utils.Tools;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * @ClassName : SectorServiceImpl  //类名
 * @Description : 区域服务接口实现类  //描述
 * @Author : 易嵘  //作者
 * @Date: 2020-06-07 10:47  //时间
 */
@Service
public class SectorServiceImpl implements SectorService {

    /**
     * 区域dao
     */
    @Resource
    TenementSectorMapper sectorMapper;

    /**
     * 查询所有（分页，条件）
     * @param sector 区域模型
     * @param page 当前页数
     * @param limit 当前行数
     * @param startDate 开始使劲按
     * @param endDate 结束时间
     * @return
     */
    @Override
    public List<TenementSector> findAll(TenementSector sector, Integer page, Integer limit, String startDate, String endDate) {
        PageHelper.startPage(page,limit);
        return sectorMapper.findAll(sector,startDate,endDate);
    }

    /**
     * 查询所有
     * @return
     */
    @Override
    public List<TenementSector> selectAll() {
        return sectorMapper.selectAll();
    }

    /**
     * 总行数
     * @param sector 区域模型
     * @param startDate 开始时间
     * @param endDate 结束时间
     * @return
     */
    @Override
    public Long overCount(TenementSector sector, String startDate, String endDate) {
        return sectorMapper.overCount(sector,startDate,endDate);
    }

    /**
     * 新增
     * @param sector
     * @param user
     * @return
     */
    @Override
    public int add(TenementSector sector, TenementUser user) {
        sector.setSectorId(UUID.randomUUID().toString().replaceAll("-",""));
        sector.setRevision(1);
        sector.setCreatedBy(user.getUserName());
        //sector.setCreatedTime(new Date());
        return sectorMapper.insert(sector);
    }

    /**
     * 修改
     * @param sector
     * @param user
     * @return
     */
    @Override
    public int update(TenementSector sector,TenementUser user) {
        sector.setUpdatedBy(user.getUserName());
        sector.setUpdatedTime(new Date());
        return sectorMapper.updateByPrimaryKeySelective(sector);
    }


    /**
     * id删除
     * @param id
     * @return
     */
    @Override
    public int deleteById(String id) {
        return sectorMapper.deleteById(id);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @Override
    public int deleteAll(String[] ids) {
        List<String> list=new ArrayList<>(Arrays.asList(ids));
        return sectorMapper.deleteAll(list);
    }

    /**
     * id查询
     * @param id
     * @return
     */
    @Override
    public TenementSector findById(String id) {
        return sectorMapper.selectByPrimaryKey(id);
    }
}
